package com.leetcode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No268
 * @description
 * @date 2021/3/3 下午1:29
 */
public class No268 {
    public static void main(String[] args) {
        int[] nums = {9,6,4,2,3,5,7,0,1};
        int res = missingNumber(nums);
        System.out.println(res);
    }

    public static int missingNumber(int[] nums) {
        int sum = 0;
        for (int i = 1; i <= nums.length ; i++) {
            sum += i;
            sum -= nums[i - 1];
        }
        return sum;
    }

    // 两次异或
    public static int missingNumber2(int[] nums) {
        int missing = nums.length;
        for (int i = 0; i < nums.length; i++) {
            missing ^= i ^ nums[i];
        }
        return missing;
    }



}
